package cn.yuyin.item;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import cn.yuyin.jiaoyou.page.ChatPanel;
import cn.yuyin.main.Main;

public class ChatItemG extends Item{

	private TextItem textItem = null;
	private String name = "";
	private String time = "";
	public ChatItemG(int index,int x, int y, String name, String text, String time) {
		super(x, y, text);
		this.index = index;
		this.name = name;
		this.time = time;
	
		textItem = new TextItem(x, y+Main.font.getHeight()+Main.rowspace, text, Main.font2, 0);
		
		width = Main.WIDTH;
		height = Main.font.getHeight()+textItem.height+Main.rowspace;
		
		endX = x;
		endY = textItem.endY+Main.font.getHeight();
		System.out.println("endY:"+endY);
	}

	public void paint(Graphics g) {
		System.out.println("index:"+index);
		System.out.println("ChatPanel.cnumber:"+ChatPanel.cnumber);
		if(index == ChatPanel.cnumber){
			ishaveFouse = true;
		}else {
			ishaveFouse = false;
		}
		int color = g.getColor();
		if(ishaveFouse){
			g.setColor(0);
			g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM));
			if(name.equals(Main.name)){
				g.setColor(0x008040);
			}else{
				g.setColor(0x0000ff);
			}
			g.drawString(name+"  "+time, x, y, 0);
			g.setColor(0);			
			g.setFont(Main.font);
			textItem.y = y+Main.font.getHeight()+Main.rowspace;
			textItem.paint(g);
			
		}else{
			g.setColor(0);
			g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM));
			if(name.equals(Main.name)){
				g.setColor(0x008040);
			}else{
				g.setColor(0x0000ff);
			}
			g.drawString(name+"  "+time, x, y, 0);
			g.setColor(0);
			g.setFont(Main.font);
			textItem.y = y+Main.font.getHeight()+Main.rowspace;
			textItem.paint(g);
		}
		
		g.setColor(color);
	}

	public void keyReleased(int keyCode) {


	}

	public void pointerPressed(int x, int y) {
		
	}

	public void pointerReleased(int x, int y) {
		
	}


}
